package com.bill.pokerbe.controller;

import com.bill.pokerbe.model.Option;
import com.bill.pokerbe.model.OptionType;
import com.bill.pokerbe.model.Status;
import com.bill.pokerbe.service.PokerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/poker")
public class PokerController {
    @Autowired
    private PokerService pokerService;

    @GetMapping("/heart_beat")
    public Status heartBeat(String userId, String username) {
        return pokerService.heartBeat(userId, username);
    }

    @GetMapping("/init")
    public boolean init() {
        pokerService.initGame();
        return true;
    }

    @GetMapping("/start")
    public boolean start() {
        pokerService.startGame();
        return true;
    }

    @GetMapping("/action")
    public String action(String userId, OptionType optionType,
                         @RequestParam(required = false, defaultValue = "0") int optionNum) {
        Option option = new Option(optionType, optionNum);
        return pokerService.action(userId, option);
    }

    @GetMapping("/addMoney")
    public String addMoney(String userId, int amount) {
        return pokerService.addMoney(userId, amount);
    }
}
